package com.zcyr.service;

import com.zcyr.exception.GiteeLoginException;
import com.zcyr.util.GiteeTool;
import com.zcyr.pojo.UserInfo;
import com.zcyr.pojo.GiteeUserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    GiteeTool giteeTool;

    public UserInfo giteeLogin(String code) throws GiteeLoginException {
        GiteeUserToken giteeUserToken =  giteeTool.getUserToken(code);
        if (giteeUserToken == null){
            throw new GiteeLoginException("无效的用户code");
        }
        return giteeTool.getUserInfo(giteeUserToken);
    }
}
